package
{
	import de.nulldesign.nd2d.display.Sprite2D;
	import de.nulldesign.nd2d.materials.texture.Texture2D;
	
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.display3D.textures.Texture;
	import flash.geom.Point;
	import flash.geom.Vector3D;

	public class GameObject implements IRenderable
	{
		private var m_position:Vector3D;
		private var m_display:Sprite2D;
		
		private var m_destination:Vector3D;
		private var m_distanceLeft:Number;
		
		public function GameObject()
		{
			var rect:Sprite = SpriteUtil.getRect(5,5);
			var bmd:BitmapData = new BitmapData(rect.width, rect.height);
			bmd.draw(rect);
			var texture2d:Texture2D = Texture2D.textureFromBitmapData(bmd);
			m_display = new Sprite2D(texture2d);
		}
		
		public function setDisplayPosition(pos:Vector3D):void{
			m_display.x = pos.x;
			m_display.y = pos.y;
		}
		
		public function getPosition():Vector3D{
			return m_position;
		}
		
		public function setPosition(pos:Vector3D):void{
			m_position = pos;
		}
		
		public function setParent(parent:Scene):void{
			parent.addChild(m_display);
		}
		
		public function update():void{
			if(m_destination == null || m_distanceLeft <= 0){
				m_destination = new Vector3D(Math.floor(Math.random()*10),Math.floor(Math.random()*10),0);
				m_distanceLeft = m_position.subtract(m_destination).length;
			}
			var delta:Vector3D = m_destination.subtract(m_position);
			delta.normalize();
			delta.scaleBy(.01);
			
			m_distanceLeft -= delta.length;
			
			m_position = m_position.add(delta);
		}
	}
}